import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;

public class ClaseVista extends JFrame {

	private static final long serialVersionUID = 1L;

	private static String DesaOp = "Desa/Op", Qa = "QA";
	private static int varRBtnSelection = 0;
	private JMenuBar mb;
	private JMenu menu1;
	private JMenuItem mi1;
	static ClaseVista myFrame;
	static int countMe = 0;
	JPanel northPanel;
	JLabel lblJCL;
	JTextField txtPathJCL;
	JButton btnLoadJCL;
	JPanel centerPanel;
	JScrollPane centerPanelScroll;
	JPanel southPanel;
	JButton btnGeneraJcl;
	JButton btnSalir;
	JRadioButton rbtnDesaOp;
	JRadioButton rbtnQa;
	JLabel lblUser;
	JTextField txtUser;
	ClaseVista me;

	public enum Opciones {
		DataStage, DS_Mltiple_Inst, CopyA, CopyE, Refresco, Comentario
	}

	boolean jclModif = false;

	public ClaseVista() {
		myFrame = this;

	}

	public void prepareUI() {

		// NORTH PANEL
		northPanel = new JPanel();
		northPanel.setLayout(new BoxLayout(northPanel, BoxLayout.X_AXIS));

		mb = new JMenuBar();
		setJMenuBar(mb);
		menu1 = new JMenu("Menu");
		mb.add(menu1);
		mi1 = new JMenuItem("Nuevo Jcl");
		menu1.add(mi1);
		mi1.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {

				jclModif = false;
				txtPathJCL.setText("");
				txtUser.setText("");
				centerPanel.removeAll();
				ClaseSubVista nuevalinea = null;
				nuevalinea = new ClaseSubVista(Opciones.DataStage, false, "", "", "");
				centerPanel.add(nuevalinea, 0);
				myFrame.repaint();
				myFrame.pack();

			}
		});

		lblJCL = new JLabel("JCL");
		txtPathJCL = new JTextField(20);
		btnLoadJCL = new JButton("...");

		northPanel.add(lblJCL, 0);
		northPanel.add(txtPathJCL, 1);
		northPanel.add(btnLoadJCL, 2);

		// CENTER PANEL
		centerPanel = new JPanel();
		centerPanel.setLayout(new BoxLayout(centerPanel, BoxLayout.Y_AXIS));
		centerPanel.add(new ClaseSubVista(), 0);
		centerPanelScroll = new JScrollPane(centerPanel);
		centerPanelScroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
		centerPanelScroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

		centerPanelScroll.add(centerPanel);
		centerPanelScroll.setViewportView(centerPanel);

		// SOUTH PANEL
		southPanel = new JPanel();
		southPanel.setLayout(new GridLayout(2, 3));

		rbtnDesaOp = new JRadioButton(DesaOp);
		rbtnDesaOp.setActionCommand(DesaOp);
		rbtnDesaOp.setSelected(true);

		rbtnQa = new JRadioButton(Qa);
		rbtnQa.setActionCommand(Qa);

		// Group the radio buttons.
		ButtonGroup rbtnGroup = new ButtonGroup();
		rbtnGroup.add(rbtnDesaOp);
		rbtnGroup.add(rbtnQa);

		// Register a listener for the radio buttons.
		RadioListener myListener = new RadioListener();
		rbtnDesaOp.addActionListener(myListener);
		rbtnQa.addActionListener(myListener);

		btnGeneraJcl = new JButton("Generar JCL");

		btnSalir = new JButton("Salir");
		btnSalir.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				System.exit(0);
			}
		});

		txtUser = new JTextField();

		southPanel.add(new JLabel("Usuario"));
		southPanel.add(rbtnDesaOp);
		southPanel.add(btnGeneraJcl);
		southPanel.add(txtUser);
		southPanel.add(rbtnQa);
		southPanel.add(btnSalir);

		getContentPane().add(northPanel, BorderLayout.PAGE_START);
		getContentPane().add(centerPanelScroll, BorderLayout.CENTER);
		getContentPane().add(southPanel, BorderLayout.PAGE_END);

	}

	private class RadioListener implements ActionListener {
		@Override
		public void actionPerformed(ActionEvent e) {
			if (e.getActionCommand() == DesaOp) {
				varRBtnSelection = 0;
			} else {
				varRBtnSelection = 1;
			}
		}
	}

	public String getTxtPathJCL() {
		return txtPathJCL.getText();
	}

	public Component[] getLineComponents() {
		return centerPanel.getComponents();
	}

	public boolean getJclModif() {
		return jclModif;
	}

	public void setJclModif(boolean JclModifset) {
		jclModif  = JclModifset;
	}
	
	public String getTxtUser() {
		return txtUser.getText();
	}

	public int getVarRBtnSelection() {
		return varRBtnSelection;
	}

	public void setTxtPathJCL(String path) {
		txtPathJCL.setText(path);

	}

}
